package com.fenghuajueli.module_find_the_difference;

import android.content.Context;
import android.content.SharedPreferences;

public class SPHelper {

    private volatile static SPHelper instance;

    public static SPHelper getInstance(Context context) {
        if (instance == null) {
            synchronized (SPHelper.class) {
                if (instance == null) {
                    instance = new SPHelper(context.getApplicationContext());
                }
            }
        }
        return instance;
    }

    private static final String KEY_ALREADY_GUIDE = "already_guide";

    private static final String KEY_TISHI_COUNT = "tishi_count";
    private static final String KEY_MUSIC = "music";
    private static final String INDEX = "index";
    private static final String ISWATCHED = "is_watched"; // 是否看完激励视频
    private static final String ISWATCHEDCY = "is_watched_chengyu"; // 是否看完激励视频

    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    private SPHelper(Context context) {
        sharedPreferences = context.getSharedPreferences("Config", Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public boolean setMusic(boolean o) {
        editor.putBoolean(KEY_MUSIC, o);
        return editor.commit();
    }

    public boolean getMusic() {
        return sharedPreferences.getBoolean(KEY_MUSIC, false);
    }

    public boolean setTishiCount(int o) {
        editor.putInt(KEY_TISHI_COUNT, o);
        return editor.commit();
    }

    public int getTishiCount() {
        return sharedPreferences.getInt(KEY_TISHI_COUNT, 0);
    }

    public boolean setAlreadyGuide(boolean o) {
        editor.putBoolean(KEY_ALREADY_GUIDE, o);
        return editor.commit();
    }

    public boolean getAlreadyGuide() {
        return sharedPreferences.getBoolean(KEY_ALREADY_GUIDE, false);
    }

    public boolean setIndex(int index) {
        editor.putInt(INDEX, index);
        return editor.commit();
    }

    public int getIndex() {
        return sharedPreferences.getInt(INDEX, 0);
    }

    public boolean setIsWatched(boolean index) {
        editor.putBoolean(ISWATCHED, index);
        return editor.commit();
    }

    public boolean getIsWatched() {
        return sharedPreferences.getBoolean(ISWATCHED, false);
    }

    public boolean setIsWatchedCY(boolean index) {
        editor.putBoolean(ISWATCHEDCY, index);
        return editor.commit();
    }

    public boolean getIsWatchedCY() {
        return sharedPreferences.getBoolean(ISWATCHEDCY, false);
    }
}
